package org.me.marble;

import android.view.KeyEvent;
import android.content.Context;
import android.content.SharedPreferences;

/**
 *
 * @author tungi
 */

public class PushPopOptions{

    //saves the current game state and options
    public static void push(MainActivity main){
        SharedPreferences.Editor ed=
                    main.getSharedPreferences(Context.ACTIVITY_SERVICE,
                    Context.MODE_PRIVATE).edit();

        ed.putBoolean("started",OptionsLibrary.started);
        ed.putBoolean("sound",OptionsLibrary.sound);
        ed.putBoolean("vibrate",OptionsLibrary.vibrate);
        ed.putBoolean("onscreen",OptionsLibrary.onscreen);
        ed.putBoolean("tilt_control",OptionsLibrary.tilt_control);
        ed.putBoolean("shadow",OptionsLibrary.shadow);
        ed.putBoolean("fps",OptionsLibrary.fps);

        ed.putInt("bestNormal",OptionsLibrary.bestNormal);
        ed.putInt("bestPoint",OptionsLibrary.bestPoint);
        ed.putInt("lifes",OptionsLibrary.lifes);
        ed.putInt("current_level",OptionsLibrary.current_level);
        ed.putInt("reached_level",OptionsLibrary.reached_level);
        ed.putInt("difficulty_level",OptionsLibrary.difficulty_level);
        ed.putInt("left_key",OptionsLibrary.left_key);
        ed.putInt("right_key",OptionsLibrary.right_key);
        ed.putInt("key_sensitivity",OptionsLibrary.key_sensitivity);
        ed.putInt("tilt_sensitivity",OptionsLibrary.tilt_sensitivity);

        ed.putFloat("points",OptionsLibrary.points);
        ed.putFloat("bestTime",OptionsLibrary.bestTime);
        ed.putFloat("tilt_orientation",OptionsLibrary.tilt_orientation);

        ed.putString("game_type",OptionsLibrary.game_type);
        ed.putString("grahics_quality",OptionsLibrary.graphics_quality);
        ed.putString("objects_quality",OptionsLibrary.objects_quality);
        ed.putString("textures_quality",OptionsLibrary.texture_quality);

        ed.commit();
    }

    //get the last game states and options
    public static void pop(MainActivity main){
        SharedPreferences sd=
                    main.getSharedPreferences(Context.ACTIVITY_SERVICE,
                    Context.MODE_PRIVATE);

        OptionsLibrary.started=sd.getBoolean("started",false);
        OptionsLibrary.sound=sd.getBoolean("sound",false);
        OptionsLibrary.vibrate=sd.getBoolean("vibrate",true);
        OptionsLibrary.onscreen=sd.getBoolean("onscreen",false);
        OptionsLibrary.tilt_control=sd.getBoolean("tilt_control",false);
        OptionsLibrary.shadow=sd.getBoolean("shadow",false);
        OptionsLibrary.fps=sd.getBoolean("fps",true);

        OptionsLibrary.bestNormal=sd.getInt("bestNormal",0);
        OptionsLibrary.bestPoint=sd.getInt("bestPoint",0);
        OptionsLibrary.lifes=sd.getInt("lifes",3);
        OptionsLibrary.current_level=sd.getInt("current_level",1);
        OptionsLibrary.reached_level=sd.getInt("reached_level",1);
        OptionsLibrary.difficulty_level=sd.getInt("difficulty_level",1);
        OptionsLibrary.left_key=sd.getInt("left_key",KeyEvent.KEYCODE_DPAD_LEFT);
        OptionsLibrary.right_key=sd.getInt("right_key",KeyEvent.KEYCODE_DPAD_RIGHT);
        OptionsLibrary.key_sensitivity=sd.getInt("key_sensitivity",5);
        OptionsLibrary.tilt_sensitivity=sd.getInt("tilt_sensitivity",10);

        OptionsLibrary.points=sd.getFloat("points",0.0f);
        OptionsLibrary.bestTime=sd.getFloat("bestTime",0.0f);
        OptionsLibrary.tilt_orientation=sd.getFloat("tilt_orientation",0.0f);

        OptionsLibrary.game_type=sd.getString("game_type","normal");
        OptionsLibrary.graphics_quality=sd.getString("grahics_quality","high");
        OptionsLibrary.objects_quality=sd.getString("objects_quality","medium");
        OptionsLibrary.texture_quality=sd.getString("textures_quality","low");
    }
}
